import { defineStore } from "pinia";
import { store } from "@/store";
import { useUserStoreHook } from "@/store/modules/user";
import { getAdmin, AdminInfo } from "@/api/admin";

export type stateType = {
  total: number;
  adminList: Array<AdminInfo>;
};

export const useAdminStore = defineStore({
  id: "pure-Admin",
  state: (): stateType => ({
    adminList: [],
    total: 0
  }),
  actions: {
    async getAdminInfo(currentPage: number, pigeSize: number) {
      await getAdmin({
        id: useUserStoreHook().manageId,
        currentPage,
        pigeSize
      }).then(data => {
        this.total = data.total;
        this.adminList = data.list;
      });
    }
  }
});

export function useAdminStoreHook() {
  return useAdminStore(store);
}
